package com.bwie.service.impl;

import com.bwie.common.constants.JwtConstants;
import com.bwie.common.constants.TokenConstants;
import com.bwie.common.pojo.po.OrderPo;
import com.bwie.common.pojo.po.UserPo;
import com.bwie.common.result.Result;
import com.bwie.mapper.OrderMapper;
import com.bwie.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private HttpServletRequest request;
    @Override
    public Result list() {
        String header = request.getHeader(TokenConstants.TOKEN);
        UserPo userPo = (UserPo) redisTemplate.opsForValue().get(JwtConstants.USER_KEY + header);
        List<Integer> goodsId = orderMapper.list(userPo.getUserId());
        //查询订单
        List<OrderPo> list = orderMapper.orderList(goodsId);
        return Result.success(list);
    }
}
